<ui:composition template="index.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

	<ui:define name="content">
		<h3 id="title-doc">
			<a href="" data-reveal-id="dlg-new" class="icon-plus"></a> | Tags
		</h3>

		<p:dataTable id="dataTable" var="tag" value="#{tagBean.tags}"
			paginator="true" rows="25"
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
			rowsPerPageTemplate="25, 50, 75, 100">

			<p:column>
				<f:facet name="header">
					<h:outputText value="Nome" />
				</f:facet>
				<h:outputText value="#{tag.name}" />
			</p:column>

			<p:column>
				<f:facet name="header">
					<h:outputText value="Ações" />
				</f:facet>
				<span data-reveal-id="dlg-update"> <p:commandButton
						actionListener="#{tagBean.select}" value="Alterar"
						update="@(#form-update)" process="dataTable" />
				</span>
				<p:commandButton action="#{tagBean.delete}"
					actionListener="#{tagBean.select}" value="Excluir"
					update="dataTable" process="dataTable" />
			</p:column>
		</p:dataTable>
	</ui:define>

	<!-- Dialogs -->
	<ui:define name="dialogs">
		<div id="dlg-new" class="reveal-modal medium">
			<a class="close-reveal-modal">&#215;</a>
			<h3>Adicionar Tag</h3>

			<h:form id="form-new">
				<p:messages id="msg-new" autoUpdate="true" closable="true"
					showDetail="false" />

				<h:outputText for="new-name" value="Nome" />
				<p:inputText id="new-name" value="#{tagBean.tag.name}"
					required="true" validator="validaAlfaNumerico"
					requiredMessage="Favor informar o nome!" />

				<p:commandButton actionListener="#{tagBean.save}"
					oncomplete="validateForm(xhr, status, args, 'dlg-new')"
					value="Salvar" update="form-new" process="form-new" />
				<p:button value="Cancelar" />
			</h:form>
		</div>

		<div id="dlg-update" class="reveal-modal medium">
			<a class="close-reveal-modal">&#215;</a>
			<h3>Alterar Tag</h3>

			<h:form id="form-update">
				<p:messages id="msg-update" autoUpdate="true" closable="true"
					showDetail="false" />

				<h:outputText for="update-name" value="Nome" />
				<p:inputText id="update-name" value="#{tagBean.tag.name}"
					required="true" validator="validaAlfaNumerico"
					requiredMessage="Favor informar o nome!" />

				<p:commandButton actionListener="#{tagBean.update}"
					oncomplete="validateForm(xhr, status, args, 'dlg-update')"
					value="Salvar" update="form-update" process="form-update" />
				<p:button value="Cancelar" />
			</h:form>
		</div>
	</ui:define>

</ui:composition>